home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gas_251.zip / bin_251 / bfd / hp300hpux.c < prev    next >
C/C++ Source or Header  |  1994-08-02  |  27KB  |  885 lines

  1. /* BFD backend for hp-ux 9000/300
  2.    Copyright (C) 1990, 1991, 1994 Free Software Foundation, Inc.
  3.    Written by Glenn Engel.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /*
  22.  
  23.     hpux native  ------------> |               |
  24.                                | hp300hpux bfd | ----------> hpux w/gnu ext
  25.     hpux w/gnu extension ----> |               |
  26.  
  27.  
  28.     Support for the 9000/[34]00 has several limitations.
  29.       1. Shared libraries are not supported.
  30.       2. The output format from this bfd is not usable by native tools.
  31.  
  32.     The primary motivation for writing this bfd was to allow use of
  33.     gdb and gcc for host based debugging and not to mimic the hp-ux tools
  34.     in every detail.  This leads to a significant simplification of the
  35.     code and a leap in performance.  The decision to not output hp native
  36.     compatible objects was further strengthened by the fact that the richness
  37.     of the gcc compiled objects could not be represented without loss of
  38.     information.  For example, while the hp format supports the concept of
  39.     secondary symbols, it does not support indirect symbols.  Another
  40.     reason is to maintain backwards compatibility with older implementations
  41.     of gcc on hpux which used 'hpxt' to translate .a and .o files into a
  42.     format which could be readily understood by the gnu linker and gdb.
  43.     This allows reading hp secondary symbols and converting them into
  44.     indirect symbols but the reverse it not always possible.
  45.  
  46.     Another example of differences is that the hp format stores symbol offsets
  47.     in the object code while the gnu utilities use a field in the
  48.     relocation record for this.  To support the hp native format, the object
  49.     code would need to be patched with the offsets when producing .o files.
  50.  
  51.     The basic technique taken in this implementation is to #include the code
  52.     from aoutx.h and aout-target.h with appropriate #defines to override
  53.     code where a unique implementation is needed:
  54.  
  55.     {
  56.         #define a bunch of stuff
  57.         #include <aoutx.h>
  58.  
  59.         implement a bunch of functions
  60.  
  61.         #include "aout-target.h"
  62.     }
  63.  
  64.     The hp symbol table is a bit different than other a.out targets.  Instead
  65.     of having an array of nlist items and an array of strings, hp's format
  66.     has them mixed together in one structure.  In addition, the strings are
  67.     not null terminated.  It looks something like this:
  68.  
  69.     nlist element 1
  70.     string1
  71.     nlist element 2
  72.     string2
  73.     ...
  74.  
  75.     The whole symbol table is read as one chunk and then we march thru it
  76.     and convert it to canonical form.  As we march thru the table, we copy
  77.     the nlist data into the internal form and we compact the strings and null
  78.     terminate them, using storage from the already allocated symbol table:
  79.  
  80.     string1
  81.     null
  82.     string2
  83.     null
  84.  */
  85.  
  86. /* @@ Is this really so different from normal a.out that it needs to include
  87.    aoutx.h?  We should go through this file sometime and see what can be made
  88.    more dependent on aout32.o and what might need to be broken off and accessed
  89.    through the backend_data field.  Or, maybe we really do need such a
  90.    completely separate implementation.  I don't have time to investigate this
  91.    much further right now.  [raeburn:19930428.2124EST] */
  92. /* @@ Also, note that there wind up being two versions of some routines, with
  93.    different names, only one of which actually gets used.  For example:
  94.     slurp_symbol_table
  95.     swap_std_reloc_in
  96.     slurp_reloc_table
  97.     get_symtab
  98.     get_symtab_upper_bound
  99.     canonicalize_reloc
  100.     mkobject
  101.    This should also be fixed.  */
  102.  
  103. #define TARGETNAME "a.out-hp300hpux"
  104. #define MY(OP) CAT(hp300hpux_,OP)
  105.  
  106. #define external_exec hp300hpux_exec_bytes
  107. #define external_nlist hp300hpux_nlist_bytes
  108.  
  109. #include "aout/hp300hpux.h"
  110.  
  111. /* define these so we can compile unused routines in aoutx.h */
  112. #define e_strx  e_shlib
  113. #define e_other e_length
  114. #define e_desc  e_almod
  115.  
  116. #define AR_PAD_CHAR '/'
  117. #define TARGET_IS_BIG_ENDIAN_P
  118. #define DEFAULT_ARCH bfd_arch_m68k
  119.  
  120. #define MY_get_section_contents aout_32_get_section_contents
  121. #define MY_slurp_armap bfd_slurp_bsd_armap_f2
  122.  
  123. /***********************************************/
  124. /* provide overrides for routines in this file */
  125. /***********************************************/
  126. /* these don't use MY because that causes problems within JUMP_TABLE
  127.    (CAT winds up being expanded recursively, which ANSI C compilers
  128.    will not do).  */
  129. #define MY_get_symtab hp300hpux_get_symtab
  130. #define MY_get_symtab_upper_bound hp300hpux_get_symtab_upper_bound
  131. #define MY_canonicalize_reloc hp300hpux_canonicalize_reloc
  132. #define MY_write_object_contents hp300hpux_write_object_contents
  133.  
  134. #define MY_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
  135. #define MY_bfd_link_add_symbols _bfd_generic_link_add_symbols
  136. #define MY_final_link_callback unused
  137. #define MY_bfd_final_link _bfd_generic_final_link
  138.  
  139. /* Until and unless we convert the slurp_reloc and slurp_symtab
  140.    routines in this file, we can not use the default aout
  141.    free_cached_info routine which assumes that the relocs and symtabs
  142.    were allocated using malloc.  */
  143. #define MY_bfd_free_cached_info bfd_true
  144.  
  145. #define hp300hpux_write_syms aout_32_write_syms
  146.  
  147. #define MY_callback MY(callback)
  148.  
  149. #define MY_exec_hdr_flags 0x2
  150.  
  151. #define NAME_swap_exec_header_in NAME(hp300hpux_32_,swap_exec_header_in)
  152.  
  153. #define HP_SYMTYPE_UNDEFINED    0x00
  154. #define HP_SYMTYPE_ABSOLUTE    0x01
  155. #define HP_SYMTYPE_TEXT        0x02
  156. #define HP_SYMTYPE_DATA        0x03
  157. #define HP_SYMTYPE_BSS        0x04
  158. #define HP_SYMTYPE_COMMON    0x05
  159.  
  160. #define HP_SYMTYPE_TYPE        0x0F
  161. #define HP_SYMTYPE_FILENAME    0x1F
  162.  
  163. #define HP_SYMTYPE_ALIGN    0x10
  164. #define HP_SYMTYPE_EXTERNAL    0x20
  165. #define HP_SECONDARY_SYMBOL     0x40
  166.  
  167. /* RELOCATION DEFINITIONS */
  168. #define HP_RSEGMENT_TEXT    0x00
  169. #define HP_RSEGMENT_DATA    0x01
  170. #define HP_RSEGMENT_BSS        0x02
  171. #define HP_RSEGMENT_EXTERNAL    0x03
  172. #define HP_RSEGMENT_PCREL       0x04
  173. #define HP_RSEGMENT_RDLT        0x05
  174. #define HP_RSEGMENT_RPLT        0x06
  175. #define HP_RSEGMENT_NOOP    0x3F
  176.  
  177. #define HP_RLENGTH_BYTE        0x00
  178. #define HP_RLENGTH_WORD        0x01
  179. #define HP_RLENGTH_LONG        0x02
  180. #define HP_RLENGTH_ALIGN    0x03
  181.  
  182. #define NAME(x,y) CAT3(hp300hpux,_32_,y)
  183. #define ARCH_SIZE 32
  184.  
  185. /* aoutx.h requires definitions for BMAGIC and QMAGIC.  */
  186. #define BMAGIC HPUX_DOT_O_MAGIC
  187. #define QMAGIC 0314
  188.  
  189. #include "aoutx.h"
  190.  
  191. /* Since the hpux symbol table has nlist elements interspersed with
  192.    strings and we need to insert som strings for secondary symbols, we
  193.    give ourselves a little extra padding up front to account for
  194.    this.  Note that for each non-secondary symbol we process, we gain
  195.    9 bytes of space for the discarded nlist element (one byte used for
  196.    null).  SYM_EXTRA_BYTES is the extra space.  */
  197. #define SYM_EXTRA_BYTES   1024
  198.  
  199. /* Set parameters about this a.out file that are machine-dependent.
  200.    This routine is called from some_aout_object_p just before it returns.  */
  201. static const bfd_target *
  202. MY (callback) (abfd)
  203.      bfd *abfd;
  204. {
  205.   struct internal_exec *execp = exec_hdr (abfd);
  206.  
  207.   /* Calculate the file positions of the parts of a newly read aout header */
  208.   obj_textsec (abfd)->_raw_size = N_TXTSIZE (*execp);
  209.  
  210.   /* The virtual memory addresses of the sections */
  211.   obj_textsec (abfd)->vma = N_TXTADDR (*execp);
  212.   obj_datasec (abfd)->vma = N_DATADDR (*execp);
  213.   obj_bsssec (abfd)->vma = N_BSSADDR (*execp);
  214.  
  215.   /* The file offsets of the sections */
  216.   obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
  217.   obj_datasec (abfd)->filepos = N_DATOFF (*execp);
  218.  
  219.   /* The file offsets of the relocation info */
  220.   obj_textsec (abfd)->rel_filepos = N_TRELOFF (*execp);
  221.   obj_datasec (abfd)->rel_filepos = N_DRELOFF (*execp);
  222.  
  223.   /* The file offsets of the string table and symbol table.  */
  224.   obj_sym_filepos (abfd) = N_SYMOFF (*execp);
  225.   obj_str_filepos (abfd) = N_STROFF (*execp);
  226.  
  227.   /* Determine the architecture and machine type of the object file.  */
  228. #ifdef SET_ARCH_MACH
  229.   SET_ARCH_MACH (abfd, *execp);
  230. #else
  231.   bfd_default_set_arch_mach (abfd, DEFAULT_ARCH, 0);
  232. #endif
  233.  
  234.  
  235.   if (obj_aout_subformat (abfd) == gnu_encap_format)
  236.     {
  237.       /* The file offsets of the relocation info */
  238.       obj_textsec (abfd)->rel_filepos = N_GNU_TRELOFF (*execp);
  239.       obj_datasec (abfd)->rel_filepos = N_GNU_DRELOFF (*execp);
  240.  
  241.       /* The file offsets of the string table and symbol table.  */
  242.       obj_sym_filepos (abfd) = N_GNU_SYMOFF (*execp);
  243.       obj_str_filepos (abfd) = (obj_sym_filepos (abfd) + execp->a_syms);
  244.  
  245.       abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
  246.       bfd_get_symcount (abfd) = execp->a_syms / 12;
  247.       obj_symbol_entry_size (abfd) = 12;
  248.       obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
  249.     }
  250.  
  251.   return abfd->xvec;
  252. }
  253.  
  254. extern boolean aout_32_write_syms PARAMS ((bfd * abfd));
  255.  
  256. static boolean
  257. MY (write_object_contents) (abfd)
  258.      bfd *abfd;
  259. {
  260.   struct external_exec exec_bytes;
  261.   struct internal_exec *execp = exec_hdr (abfd);
  262.   bfd_size_type text_size;    /* dummy vars */
  263.   file_ptr text_end;
  264.  
  265.   memset (&exec_bytes, 0, sizeof (exec_bytes));
  266. #if CHOOSE_RELOC_SIZE
  267.   CHOOSE_RELOC_SIZE (abfd);
  268. #else
  269.   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
  270. #endif
  271.  
  272.   if (adata (abfd).magic == undecided_magic)
  273.     NAME (aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end);
  274.   execp->a_syms = 0;
  275.  
  276.   execp->a_entry = bfd_get_start_address (abfd);
  277.  
  278.   execp->a_trsize = ((obj_textsec (abfd)->reloc_count) *
  279.              obj_reloc_entry_size (abfd));
  280.   execp->a_drsize = ((obj_datasec (abfd)->reloc_count) *
  281.              obj_reloc_entry_size (abfd));
  282.  
  283.   N_SET_MACHTYPE (*execp, 0xc);
  284.   N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags);
  285.  
  286.   NAME (aout,swap_exec_header_out) (abfd, execp, &exec_bytes);
  287.  
  288.   /* update fields not covered by default swap_exec_header_out */
  289.  
  290.   /* this is really the sym table size but we store it in drelocs */
  291.   bfd_h_put_32 (abfd, bfd_get_symcount (abfd) * 12, exec_bytes.e_drelocs);
  292.  
  293.   if (bfd_seek (abfd, 0L, false) != 0
  294.       || (bfd_write ((PTR) & exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
  295.       != EXEC_BYTES_SIZE))
  296.     return false;
  297.  
  298.   /* Write out the symbols, and then the relocs.  We must write out
  299.        the symbols first so that we know the symbol indices.  */
  300.  
  301.   if (bfd_get_symcount (abfd) != 0)
  302.     {
  303.       /* Skip the relocs to where we want to put the symbols.  */
  304.       if (bfd_seek (abfd, (file_ptr) N_DRELOFF (*execp) + execp->a_drsize,
  305.             SEEK_SET) != 0)
  306.     return false;
  307.     }
  308.  
  309.   if (!MY (write_syms) (abfd))
  310.     return false;
  311.  
  312.   if (bfd_get_symcount (abfd) != 0)
  313.     {
  314.       if (bfd_seek (abfd, (long) (N_TRELOFF (*execp)), false) != 0)
  315.     return false;
  316.       if (!NAME (aout,squirt_out_relocs) (abfd, obj_textsec (abfd)))
  317.     return false;
  318.       if (bfd_seek (abfd, (long) (N_DRELOFF (*execp)), false) != 0)
  319.     return false;
  320.       if (!NAME (aout,squirt_out_relocs) (abfd, obj_datasec (abfd)))
  321.     return false;
  322.     }
  323.  
  324.   return true;
  325. }
  326.  
  327. /* convert the hp symbol type to be the same as aout64.h usage so we */
  328. /* can piggyback routines in aoutx.h.                                */
  329.  
  330. static void
  331. convert_sym_type (sym_pointer, cache_ptr, abfd)
  332.      struct external_nlist *sym_pointer;
  333.      aout_symbol_type *cache_ptr;
  334.      bfd *abfd;
  335. {
  336.   int name_type;
  337.   int new_type;
  338.  
  339.   name_type = (cache_ptr->type);
  340.   new_type = 0;
  341.  
  342.   if ((name_type & HP_SYMTYPE_ALIGN) != 0)
  343.     {
  344.       /* iou_error ("aligned symbol encountered: %s", name);*/
  345.       name_type = 0;
  346.     }
  347.  
  348.   if (name_type == HP_SYMTYPE_FILENAME)
  349.     new_type = N_FN;
  350.   else
  351.     {
  352.       switch (name_type & HP_SYMTYPE_TYPE)
  353.     {
  354.     case HP_SYMTYPE_UNDEFINED:
  355.       new_type = N_UNDF;
  356.       break;
  357.  
  358.     case HP_SYMTYPE_ABSOLUTE:
  359.       new_type = N_ABS;
  360.       break;
  361.  
  362.     case HP_SYMTYPE_TEXT:
  363.       new_type = N_TEXT;
  364.       break;
  365.  
  366.     case HP_SYMTYPE_DATA:
  367.       new_type = N_DATA;
  368.       break;
  369.  
  370.     case HP_SYMTYPE_BSS:
  371.       new_type = N_BSS;
  372.       break;
  373.  
  374.     case HP_SYMTYPE_COMMON:
  375.       new_type = N_COMM;
  376.       break;
  377.  
  378.     default:
  379.       fprintf (stderr, "unknown symbol type encountered: %x", name_type);
  380.     }
  381.       if (name_type & HP_SYMTYPE_EXTERNAL)
  382.     new_type |= N_EXT;
  383.  
  384.       if (name_type & HP_SECONDARY_SYMBOL)
  385.     new_type = (new_type & ~N_TYPE) | N_INDR;
  386.     }
  387.   cache_ptr->type = new_type;
  388.  
  389. }
  390.  
  391.  
  392. /*
  393. DESCRIPTION
  394.         Swaps the information in an executable header taken from a raw
  395.         byte stream memory image, into the internal exec_header
  396.         structure.
  397. */
  398.  
  399. void
  400. NAME (aout,swap_exec_header_in) (abfd, raw_bytes, execp)
  401.      bfd *abfd;
  402.      struct external_exec *raw_bytes;
  403.      struct internal_exec *execp;
  404. {
  405.   struct external_exec *bytes = (struct external_exec *) raw_bytes;
  406.  
  407.   /* The internal_exec structure has some fields that are unused in this
  408.      configuration (IE for i960), so ensure that all such uninitialized
  409.      fields are zero'd out.  There are places where two of these structs
  410.      are memcmp'd, and thus the contents do matter. */
  411.   memset (execp, 0, sizeof (struct internal_exec));
  412.   /* Now fill in fields in the execp, from the bytes in the raw data.  */
  413.   execp->a_info = bfd_h_get_32 (abfd, bytes->e_info);
  414.   execp->a_text = GET_WORD (abfd, bytes->e_text);
  415.   execp->a_data = GET_WORD (abfd, bytes->e_data);
  416.   execp->a_bss = GET_WORD (abfd, bytes->e_bss);
  417.   execp->a_syms = GET_WORD (abfd, bytes->e_syms);
  418.   execp->a_entry = GET_WORD (abfd, bytes->e_entry);
  419.   execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
  420.   execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
  421.  
  422.   /***************************************************************/
  423.   /* check the header to see if it was generated by a bfd output */
  424.   /* this is detected rather bizarely by requiring a bunch of    */
  425.   /* header fields to be zero and an old unused field (now used) */
  426.   /* to be set.                                                  */
  427.   /***************************************************************/
  428.   do
  429.     {
  430.       long syms;
  431.       struct aout_data_struct *rawptr;
  432.       if (bfd_h_get_32 (abfd, bytes->e_passize) != 0)
  433.     break;
  434.       if (bfd_h_get_32 (abfd, bytes->e_syms) != 0)
  435.     break;
  436.       if (bfd_h_get_32 (abfd, bytes->e_supsize) != 0)
  437.     break;
  438.  
  439.       syms = bfd_h_get_32 (abfd, bytes->e_drelocs);
  440.       if (syms == 0)
  441.     break;
  442.  
  443.       /* OK, we've passed the test as best as we can determine */
  444.       execp->a_syms = syms;
  445.  
  446.       /* allocate storage for where we will store this result */
  447.       rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, sizeof (*rawptr));
  448.  
  449.       if (rawptr == NULL)
  450.     {
  451.       bfd_set_error (bfd_error_no_memory);
  452.       return;
  453.     }
  454.       abfd->tdata.aout_data = rawptr;
  455.       obj_aout_subformat (abfd) = gnu_encap_format;
  456.     }
  457.   while (0);
  458. }
  459.  
  460.  
  461. /* The hp symbol table is a bit different than other a.out targets.  Instead
  462.    of having an array of nlist items and an array of strings, hp's format
  463.    has them mixed together in one structure.  In addition, the strings are
  464.    not null terminated.  It looks something like this:
  465.  
  466.    nlist element 1
  467.    string1
  468.    nlist element 2
  469.    string2
  470.    ...
  471.  
  472.    The whole symbol table is read as one chunk and then we march thru it
  473.    and convert it to canonical form.  As we march thru the table, we copy
  474.    the nlist data into the internal form and we compact the strings and null
  475.    terminate them, using storage from the already allocated symbol table:
  476.  
  477.    string1
  478.    null
  479.    string2
  480.    null
  481.    ...
  482. */
  483.  
  484. boolean
  485. MY (slurp_symbol_table) (abfd)
  486.      bfd *abfd;
  487. {
  488.   bfd_size_type symbol_bytes;
  489.   struct external_nlist *syms;
  490.   struct external_nlist *sym_pointer;
  491.   struct external_nlist *sym_end;
  492.   char *strings;
  493.   aout_symbol_type *cached;
  494.   unsigned num_syms = 0;
  495.   unsigned num_secondary = 0;
  496.  
  497.   /* If there's no work to be done, don't do any */
  498.   if (obj_aout_symbols (abfd) != (aout_symbol_type *) NULL)
  499.     return true;
  500.   symbol_bytes = exec_hdr (abfd)->a_syms;
  501.   if (symbol_bytes == 0)
  502.     {
  503.       bfd_set_error (bfd_error_no_symbols);
  504.       return false;
  505.     }
  506.  
  507.   strings = (char *) bfd_alloc (abfd,
  508.                 symbol_bytes + SYM_EXTRA_BYTES);
  509.   if (!strings)
  510.     {
  511.       bfd_set_error (bfd_error_no_memory);
  512.       return false;
  513.     }
  514.   syms = (struct external_nlist *) (strings + SYM_EXTRA_BYTES);
  515.   if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
  516.       || bfd_read ((PTR) syms, symbol_bytes, 1, abfd) != symbol_bytes)
  517.     {
  518.       bfd_release (abfd, syms);
  519.       return false;
  520.     }
  521.  
  522.  
  523.   sym_end = (struct external_nlist *) (((char *) syms) + symbol_bytes);
  524.  
  525.   /* first, march thru the table and figure out how many symbols there are */
  526.   for (sym_pointer = syms; sym_pointer < sym_end; sym_pointer++, num_syms++)
  527.     {
  528.       if (bfd_get_8 (abfd, sym_pointer->e_type) & HP_SECONDARY_SYMBOL)
  529.     num_secondary++;
  530.       /* skip over the embedded symbol. */
  531.       sym_pointer = (struct external_nlist *) (((char *) sym_pointer) +
  532.                            sym_pointer->e_length[0]);
  533.     }
  534.  
  535.   /* now that we know the symbol count, update the bfd header */
  536.   bfd_get_symcount (abfd) = num_syms + num_secondary;
  537.  
  538.   cached = (aout_symbol_type *)
  539.     bfd_zalloc (abfd, (bfd_size_type) (bfd_get_symcount (abfd) *
  540.                        sizeof (aout_symbol_type)));
  541.   if (!cached)
  542.     {
  543.       bfd_set_error (bfd_error_no_memory);
  544.       return false;
  545.     }
  546.  
  547.   /* as we march thru the hp symbol table, convert it into a list of
  548.      null terminated strings to hold the symbol names.  Make sure any
  549.      assignment to the strings pointer is done after we're thru using
  550.      the nlist so we don't overwrite anything important. */
  551.   num_secondary = 0;
  552.  
  553.   /* OK, now walk the new symtable, cacheing symbol properties */
  554.   {
  555.     aout_symbol_type *cache_ptr = cached;
  556.     aout_symbol_type cache_save;
  557.     /* Run through table and copy values */
  558.     for (sym_pointer = syms, cache_ptr = cached;
  559.      sym_pointer < sym_end; sym_pointer++, cache_ptr++)
  560.       {
  561.     unsigned int length;
  562.     cache_ptr->symbol.the_bfd = abfd;
  563.     cache_ptr->symbol.value = GET_SWORD (abfd, sym_pointer->e_value);
  564.     cache_ptr->desc = bfd_get_16 (abfd, sym_pointer->e_almod);
  565.     cache_ptr->type = bfd_get_8 (abfd, sym_pointer->e_type);
  566.     cache_ptr->symbol.udata = 0;
  567.     length = bfd_get_8 (abfd, sym_pointer->e_length);
  568.     cache_ptr->other = length;    /* other not used, save length here */
  569.  
  570.     cache_save = *cache_ptr;
  571.     convert_sym_type (sym_pointer, cache_ptr, abfd);
  572.     if (!translate_from_native_sym_flags (abfd, cache_ptr))
  573.       return false;
  574.  
  575.     /********************************************************/
  576.     /* for hpux, the 'lenght' value indicates the length of */
  577.     /* the symbol name which follows the nlist entry.       */
  578.     /********************************************************/
  579.     if (length)
  580.       {
  581.         /**************************************************************/
  582.         /* the hp string is not null terminated so we create a new one*/
  583.         /* by copying the string to overlap the just vacated nlist    */
  584.         /* structure before it in memory.                             */
  585.         /**************************************************************/
  586.         cache_ptr->symbol.name = strings;
  587.         memcpy (strings, sym_pointer + 1, length);
  588.         strings[length] = '\0';
  589.         strings += length + 1;
  590.       }
  591.     else
  592.       cache_ptr->symbol.name = (char *) NULL;
  593.  
  594.     /**********************************************************/
  595.     /* this is a bit of a kludge, but a secondary hp symbol   */
  596.     /* gets translated into a gnu indirect symbol.  When this */
  597.     /* happens, we need to create a "dummy" record to which   */
  598.     /* we can point the indirect symbol to.                   */
  599.     /**********************************************************/
  600.     if ((cache_ptr->type | N_EXT) == (N_INDR | N_EXT))
  601.       {
  602.         aout_symbol_type *cache_ptr2 = cached + num_syms + num_secondary;
  603.  
  604.         num_secondary++;
  605.  
  606.         /* aoutx.h assumes the "next" value is the indirect sym  */
  607.         /* since we don't want to disturb the order by inserting */
  608.         /* a new symbol, we tack on the created secondary syms   */
  609.         /* at the end.                                           */
  610.         cache_ptr->symbol.value = (bfd_vma) (cache_ptr2);
  611.         *cache_ptr2 = cache_save;
  612.         cache_ptr2->symbol.name = strings;
  613.         memcpy (strings, cache_ptr->symbol.name, length);
  614.         strcpy (strings + length, ":secondry");    /* 9 max chars + null */
  615.         strings += length + 10;
  616.         cache_ptr2->type &= ~HP_SECONDARY_SYMBOL;    /* clear secondary */
  617.         convert_sym_type (sym_pointer, cache_ptr2, abfd);
  618.         if (!translate_from_native_sym_flags (abfd, cache_ptr2))
  619.           return false;
  620.       }
  621.  
  622.     /* skip over the embedded symbol. */
  623.     sym_pointer = (struct external_nlist *) (((char *) sym_pointer) +
  624.                          length);
  625.       }
  626.   }
  627.  
  628.   obj_aout_symbols (abfd) = cached;
  629.  
  630.   return true;
  631. }
  632.  
  633.  
  634.  
  635. void
  636. MY (swap_std_reloc_in) (abfd, bytes, cache_ptr, symbols)
  637.      bfd *abfd;
  638.      struct hp300hpux_reloc *bytes;
  639.      arelent *cache_ptr;
  640.      asymbol **symbols;
  641. {
  642.   int r_index;
  643.   int r_extern = 0;
  644.   unsigned int r_length;
  645.   int r_pcrel = 0;
  646.   struct aoutdata *su = &(abfd->tdata.aout_data->a);
  647.  
  648.   cache_ptr->address = bfd_h_get_32 (abfd, bytes->r_address);
  649.   r_index = bfd_h_get_16 (abfd, bytes->r_index);
  650.  
  651.   switch (bytes->r_type[0])
  652.     {
  653.     case HP_RSEGMENT_TEXT:
  654.       r_index = N_TEXT;
  655.       break;
  656.     case HP_RSEGMENT_DATA:
  657.       r_index = N_DATA;
  658.       break;
  659.     case HP_RSEGMENT_BSS:
  660.       r_index = N_BSS;
  661.       break;
  662.     case HP_RSEGMENT_EXTERNAL:
  663.       r_extern = 1;
  664.       break;
  665.     case HP_RSEGMENT_PCREL:
  666.       r_extern = 1;
  667.       r_pcrel = 1;
  668.       break;
  669.     case HP_RSEGMENT_RDLT:
  670.       break;
  671.     case HP_RSEGMENT_RPLT:
  672.       break;
  673.     case HP_RSEGMENT_NOOP:
  674.       break;
  675.     default:
  676.       fprintf (stderr, "illegal relocation segment type: %x\n",
  677.            (bytes->r_type[0]));
  678.     }
  679.  
  680.   switch (bytes->r_length[0])
  681.     {
  682.     case HP_RLENGTH_BYTE:
  683.       r_length = 0;
  684.       break;
  685.     case HP_RLENGTH_WORD:
  686.       r_length = 1;
  687.       break;
  688.     case HP_RLENGTH_LONG:
  689.       r_length = 2;
  690.       break;
  691.     default:
  692.       fprintf (stderr, "illegal relocation length: %x\n", bytes->r_length[0]);
  693.       r_length = 0;
  694.     }
  695.  
  696.   cache_ptr->howto = howto_table_std + r_length + 4 * r_pcrel;
  697.   /* FIXME-soon:  Roll baserel, jmptable, relative bits into howto setting */
  698.  
  699.   /* This macro uses the r_index value computed above */
  700.   if (r_pcrel && r_extern)
  701.     {
  702.       /* The GNU linker assumes any offset from beginning of section */
  703.       /* is already incorporated into the image while the HP linker  */
  704.       /* adds this in later.  Add it in now...                       */
  705.       MOVE_ADDRESS (-cache_ptr->address);
  706.     }
  707.   else
  708.     {
  709.       MOVE_ADDRESS (0);
  710.     }
  711. }
  712.  
  713. boolean
  714. MY (slurp_reloc_table) (abfd, asect, symbols)
  715.      bfd *abfd;
  716.      sec_ptr asect;
  717.      asymbol **symbols;
  718. {
  719.   unsigned int count;
  720.   bfd_size_type reloc_size;
  721.   PTR relocs;
  722.   arelent *reloc_cache;
  723.   size_t each_size;
  724.   struct hp300hpux_reloc *rptr;
  725.   unsigned int counter;
  726.   arelent *cache_ptr;
  727.  
  728.   if (asect->relocation)
  729.     return true;
  730.  
  731.   if (asect->flags & SEC_CONSTRUCTOR)
  732.     return true;
  733.  
  734.   if (asect == obj_datasec (abfd))
  735.     {
  736.       reloc_size = exec_hdr (abfd)->a_drsize;
  737.       goto doit;
  738.     }
  739.  
  740.   if (asect == obj_textsec (abfd))
  741.     {
  742.       reloc_size = exec_hdr (abfd)->a_trsize;
  743.       goto doit;
  744.     }
  745.  
  746.   bfd_set_error (bfd_error_invalid_operation);
  747.   return false;
  748.  
  749. doit:
  750.   if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
  751.     return false;
  752.   each_size = obj_reloc_entry_size (abfd);
  753.  
  754.   count = reloc_size / each_size;
  755.  
  756.  
  757.   reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t) (count * sizeof
  758.                             (arelent)));
  759.   if (!reloc_cache && count != 0)
  760.     {
  761.     nomem:
  762.       bfd_set_error (bfd_error_no_memory);
  763.       return false;
  764.     }
  765.  
  766.   relocs = (PTR) bfd_alloc (abfd, reloc_size);
  767.   if (!relocs && reloc_size != 0)
  768.     {
  769.       bfd_release (abfd, reloc_cache);
  770.       goto nomem;
  771.     }
  772.  
  773.   if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size)
  774.     {
  775.       bfd_release (abfd, relocs);
  776.       bfd_release (abfd, reloc_cache);
  777.       return false;
  778.     }
  779.  
  780.   rptr = (struct hp300hpux_reloc *) relocs;
  781.   counter = 0;
  782.   cache_ptr = reloc_cache;
  783.  
  784.   for (; counter < count; counter++, rptr++, cache_ptr++)
  785.     {
  786.       MY (swap_std_reloc_in) (abfd, rptr, cache_ptr, symbols);
  787.     }
  788.  
  789.  
  790.   bfd_release (abfd, relocs);
  791.   asect->relocation = reloc_cache;
  792.   asect->reloc_count = count;
  793.   return true;
  794. }
  795.  
  796.  
  797. /************************************************************************/
  798. /* The following functions are identical to functions in aoutx.h except */
  799. /* they refer to MY(func) rather than NAME(aout,func) and they also     */
  800. /* call aout_32 versions if the input file was generated by gcc         */
  801. /************************************************************************/
  802.  
  803. long aout_32_get_symtab PARAMS ((bfd * abfd, asymbol ** location));
  804. long aout_32_get_symtab_upper_bound PARAMS ((bfd * abfd));
  805.  
  806. long aout_32_canonicalize_reloc PARAMS ((bfd * abfd, sec_ptr section,
  807.                      arelent ** relptr,
  808.                      asymbol ** symbols));
  809.  
  810. long
  811. MY (get_symtab) (abfd, location)
  812.      bfd *abfd;
  813.      asymbol **location;
  814. {
  815.   unsigned int counter = 0;
  816.   aout_symbol_type *symbase;
  817.  
  818.   if (obj_aout_subformat (abfd) == gnu_encap_format)
  819.     return aout_32_get_symtab (abfd, location);
  820.  
  821.   if (!MY (slurp_symbol_table) (abfd))
  822.     return -1;
  823.  
  824.   for (symbase = obj_aout_symbols (abfd); counter++ < bfd_get_symcount (abfd);)
  825.     *(location++) = (asymbol *) (symbase++);
  826.   *location++ = 0;
  827.   return bfd_get_symcount (abfd);
  828. }
  829.  
  830. long
  831. MY (get_symtab_upper_bound) (abfd)
  832.      bfd *abfd;
  833. {
  834.   if (obj_aout_subformat (abfd) == gnu_encap_format)
  835.     return aout_32_get_symtab_upper_bound (abfd);
  836.   if (!MY (slurp_symbol_table) (abfd))
  837.     return -1;
  838.  
  839.   return (bfd_get_symcount (abfd) + 1) * (sizeof (aout_symbol_type *));
  840. }
  841.  
  842.  
  843.  
  844.  
  845. long
  846. MY (canonicalize_reloc) (abfd, section, relptr, symbols)
  847.      bfd *abfd;
  848.      sec_ptr section;
  849.      arelent **relptr;
  850.      asymbol **symbols;
  851. {
  852.   arelent *tblptr = section->relocation;
  853.   unsigned int count;
  854.   if (obj_aout_subformat (abfd) == gnu_encap_format)
  855.     return aout_32_canonicalize_reloc (abfd, section, relptr, symbols);
  856.  
  857.   if (!(tblptr || MY (slurp_reloc_table) (abfd, section, symbols)))
  858.     return -1;
  859.  
  860.   if (section->flags & SEC_CONSTRUCTOR)
  861.     {
  862.       arelent_chain *chain = section->constructor_chain;
  863.       for (count = 0; count < section->reloc_count; count++)
  864.     {
  865.       *relptr++ = &chain->relent;
  866.       chain = chain->next;
  867.     }
  868.     }
  869.   else
  870.     {
  871.       tblptr = section->relocation;
  872.  
  873.       for (count = 0; count++ < section->reloc_count;)
  874.     {
  875.       *relptr++ = tblptr++;
  876.     }
  877.     }
  878.   *relptr = 0;
  879.  
  880.   return section->reloc_count;
  881. }
  882.  
  883.  
  884. #include "aout-target.h"
  885.